package com.ay272.ssh2.meal;

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

/**
 * Created by java on 2016/5/20.
 */
//发邮件
public class textclass {
    public static void main(String[] args) throws  Exception{
        Properties pops = new Properties();
        pops.put("mail.smtp.host","smtp.qq.com");
        pops.put("mail.smtp.auth","true");
        pops.put("mail.smtp.port","465");
        pops.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
        Session session  = Session.getDefaultInstance(pops, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("asdasdbutvich@foxmail.com","wpkbiesihasrgagi");
               /* return new PasswordAuthentication("744327309@qq.com","qzcgkuahlgpjbcch");*/
            }
        });
        Message message =new MimeMessage(session);
        message.setSubject("张帆");
        message.setText("测试代码");
        Address to =new  InternetAddress("asdasdbutvich@foxmail.com");
        message.setRecipient(Message.RecipientType.TO,to);
        Address from = new InternetAddress("asdasdbutvich@foxmail.com");
        message.setFrom(from);
        Transport.send(message);
        System.out.println("发送成功");
    }
}
